package by.grsu.transport.service;

import java.util.HashMap;
import java.util.Map;

import by.grsu.transport.persistence.dao.DaoManager;
import by.grsu.transport.service.impl.LoginServiceImpl;
import by.grsu.transport.service.impl.RegistrationServiceImpl;
import by.grsu.transport.service.impl.UserServiceImpl;

public class ServiceManager {

	@SuppressWarnings("rawtypes")
	private Map<Class, Object> serviceObjects;
	private DaoManager daoManager;

	private ServiceManager() {
		super();
		this.init();
	}
	
	public static ServiceManager getDefault() {
		return new ServiceManager();
	}

	@SuppressWarnings("rawtypes")
	private void init() {
		daoManager = DaoManager.getDefault();
		serviceObjects = new HashMap<Class, Object>();

		serviceObjects.put(LoginService.class, new LoginServiceImpl(daoManager));
		serviceObjects.put(UserService.class, new UserServiceImpl(daoManager));
		serviceObjects.put(RegistrationService.class, new RegistrationServiceImpl(daoManager));

	}

	public UserService getUserService() {
		return (UserService) serviceObjects.get(UserService.class);
	}

	public LoginService getLoginService() {
		return (LoginService) serviceObjects.get(LoginService.class);
	}
	
	public RegistrationService getRegistrationService(){
		return (RegistrationService)serviceObjects.get(RegistrationService.class);
	}

}
